package org.example.src.repository;

import org.example.src.entity.FinalReport;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;

@Repository
public interface FinalReportRepository extends JpaRepository<FinalReport, Long> {
    @Query("SELECT f FROM FinalReport f WHERE f.student.id = :studentId")
    List<FinalReport> findByStudentId(@Param("studentId") Long studentId);

    @Query("SELECT f FROM FinalReport f WHERE f.application.id = :applicationId")
    List<FinalReport> findByApplicationId(@Param("applicationId") Long applicationId);

    @Query("SELECT f FROM FinalReport f WHERE f.score IS NOT NULL")
    List<FinalReport> findGradedReports();

    @Query("SELECT f FROM FinalReport f WHERE f.score IS NULL")
    List<FinalReport> findUngradedReports();

    @Query("SELECT AVG(f.score) FROM FinalReport f WHERE f.score IS NOT NULL")
    Double findAverageScore();

    @Query("SELECT COUNT(f) FROM FinalReport f WHERE f.student.id = :studentId")
    Long countByStudentId(@Param("studentId") Long studentId);
}
